package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.Order;
import com.briup.jz.bean.OrderExample;
import com.briup.jz.dao.OrderMapper;
import com.briup.jz.service.IOrderService;
import com.briup.jz.utils.CustomerException;
@Service
public class OrderServiceImpl implements IOrderService {
	@Autowired
	private OrderMapper orderMapper;
	
	@Override
	public List<Order> query(Long id) {
		OrderExample example = new OrderExample();
		if(id!=null) {
			example.createCriteria().andIdEqualTo(id);
		}
		List<Order> list = orderMapper.selectByExample(example);
		return list;			
	}

	@Override
	public void saveOrUpdate(Order order) throws CustomerException {
		if(order.getId()==null) {
			orderMapper.insert(order);
			//orderMapper.updateByPrimaryKey(order);
		}else {
			orderMapper.updateByPrimaryKey(order);

		}																
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		Order order = orderMapper.selectByPrimaryKey(id);
		if(order==null) {
			throw new CustomerException("要删除的信息不存在");
		}
		orderMapper.deleteByPrimaryKey(id);
		
	}

	@Override
	public List<Order> queryStatus(String status) {
		OrderExample example = new OrderExample();
		if(status!=null) {
			example.createCriteria().andStatusLike(status);
		}
		List<Order> list = orderMapper.selectByExample(example);
		return list;	
	}
	
}
